<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>印章的管理</title>
    <link rel="stylesheet" href="css/bootstrap.css"/>
    <script src="js/jquery.min.js" type="text/javascript"></script>
    <script src="js/vue.min.js"></script>
    <script src="js/vue-strap.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
</head>
<body>
<div id="app">
    <h1 class="text-center text">印章的管理</h1>

    <div class="row">
        <button class="btn btn-primary col-2 offset-3" @click="newSeal">新建印章</button>
        <button class="btn btn-info col-2 " @click="allSeal">所有印章</button>
        <button class="btn btn-primary col-2 " @click="showchange">显示状态</button>
    </div>
    <div class="panel panel-default" id="createseal" v-show="createshow">

        <div class="panel panel-body">
            <p class="offset-3">新建一个印章</p>
            <div class="row offset-3">

                <span class="label label-primary">印章名称：</span>
                <input class="input" placeholder="输入名称">
            </div>
            <div class="row offset-3">
                <span class="label">选择图片：</span>
                <input type="file" id="logofile" @change="upfile">
                <input type="hidden" id="filepath" value="">
            </div>
            <div class="row offset-3">
                <button class="btn btn-danger" @click="funcreateseal">创建</button>
            </div>
        </div>
    </div>
    <div class="panel" id="showallseal" v-show="!createshow">
        <div class="panel panel-body">
            <P class="offset-3">显示所有印章</P>
        </div>
    </div>
</div>
<script>
    var vue = new Vue({
        el: "#app",
        data: {
            createshow: true,
            message:""
        },
        methods: {
            newSeal: function () {
                alert("新建一个印章");
            },
            allSeal: function () {
                alert("所有的印章");
            },
            showchange: function () {
                this.createshow = !(this.createshow);
            },
            funcreateseal: function () {
                alert("提交创建印章");
            },
            upfile: function (e) {
                if (e == null || e == undefined || e == '') {
                    return false;
                }
                var formData = new window.FormData();
                formData.append('file', e.target.files[0]);
                formData.append('type', 'test');
                alert(e.target.files[0].name);
                if (!/\.(?:docx|DOCX|pdf|PDF)$/.test(e.target.files[0].name)) {
                    alert("类型必须是Word文档或者PDF文件(.docx|pdf)");
                    $('#logofile').val('');
                    return false;
                }
                $.ajax({
                    type: "POST",
                    //url: GLOBAL_INFO.WEBURL_PREFIX+"business/uploadImg.xhtml",
                    url: window.location.protocol + "//" + window.location.host + "/business/uploadImg.xhtml",
                    data: formData,
                    cache: false,
                    contentType: false,    //不可缺
                    processData: false,    //不可缺
                    dataType: "json",
                    success: function (ret) {
                        console.log(ret);
                        if (ret.code == 0) {
                            $("#filepath").val(ret.result.url);//将地址存储好
                            //$("#filepath").attr("src", ret.result.url);//显示图片
                            $("#btnCreate").enabled = true;
                            this.message = ret.result.docpath;
                            this.fileurl = ret.result.url;
                            alert(ret.message);
                        } else {
                            $("#btnCreate").enabled = false;
                            alert(ret.message);
                            $("#filepath").val("");
                            $("#logoFile").reset();
                        }
                    }.bind(this), //bind方法改变this的指向
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        alert("上传失败，请检查网络后重试");
                    }
                });

            }
        }
    })
</script>
</body>
</html>